//
//  DETabBarController.m
//  DE
//
//  Created by PEIYANG on 16/9/23.
//  Copyright © 2016年 YP. All rights reserved.
//

#import "DETabBarController.h"
#import "DEHomeController.h"
#import "DEOrderController.h"
#import "DEAudioController.h"
#import "DEBuyingController.h"
#import "DEMineController.h"
#import "DENavController.h"

#import "UIImage+Render.h"
@interface DETabBarController ()
@property(nonatomic, strong)UIView *bgView;
@end

@implementation DETabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupChildControllers];
}

/*
 * 设置全局的tabBar
 */
+ (void)load{
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    //选中状态下的文字
    NSMutableDictionary *attrSel = [NSMutableDictionary dictionary];
    attrSel[NSForegroundColorAttributeName] = [UIColor orangeColor];
    attrSel[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    
    [item setTitleTextAttributes:attrSel forState:UIControlStateSelected];
    //normal状态下的文字
    NSMutableDictionary *attrNor = [NSMutableDictionary dictionary];
    attrNor[NSForegroundColorAttributeName] = [UIColor grayColor];
    attrNor[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [item setTitleTextAttributes:attrNor forState:UIControlStateNormal];
    
    //去除tabBar顶部黑线
    [[UITabBar appearance] setShadowImage:[UIImage new]];
}

- (void)setupChildControllers{
    
    DEHomeController *home = [[DEHomeController alloc]init];
    [self initialChildController:home title:@"首页" image:@"tabbar_index_1_30x30_" highImage:@"tabbar_index_select_1_30x30_"];
//    home.view.backgroundColor = YPRandomColor;
    
    DEOrderController *order = [[DEOrderController alloc]init];
    [self initialChildController:order title:@"订阅" image:@"tabbar_index_2_30x30_" highImage:@"tabbar_index_select_2_30x30_"];
    order.view.backgroundColor = YPRandomColor;
    
    DEAudioController *audio = [[DEAudioController alloc]init];
    [self initialChildController:audio title:@"随时听" image:@"tabbar_index_3_90x60_" highImage:@"tabbar_index_select_3_90x60_"];
    audio.view.backgroundColor = YPRandomColor;
    
    DEBuyingController *buying = [[DEBuyingController alloc]init];
    [self initialChildController:buying title:@"购买" image:@"tabbar_index_4_30x30_" highImage:@"tabbar_index_select_4_30x30_"];
    buying.view.backgroundColor = YPRandomColor;
    
    DEMineController *mine = [[DEMineController alloc]init];
    [self initialChildController:mine title:@"我的" image:@"tabbar_index_5_30x30_" highImage:@"tabbar_index_select_5_30x30_"];
//    mine.view.backgroundColor = YPRandomColor;
}

- (void)initialChildController:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image highImage:(NSString *)highImage{
    if (image.length) {//image = nil / image = @""

        childVc.tabBarItem.image = [UIImage originalImageWithName:image];
        childVc.tabBarItem.selectedImage = [UIImage originalImageWithName:highImage];
        
    }
    childVc.title = title;

    DENavController *nav = [[DENavController alloc]initWithRootViewController:childVc];
    
    [self addChildViewController:nav];
}

@end
